import WsUtils, { WsCode } from "./WsUtils"

/**
 * 角色代理类
 */
export default class RoleProxy {
    private static _instance: RoleProxy = null
    public static get instance() {
        if (!this._instance) {
            this._instance = new RoleProxy()
        }
        return this._instance
    }

    /** 新角色 */
    private _newRole: NewRole = new NewRole()
    public get newRole() { return this._newRole }

    // ------------------------------网络接口------------------------------
    /** 请求创建角色 */
    reqCreateRole() {
        WsUtils.send(WsCode.CREATE_ROLE_REQ)
        cc.log('请求创建角色')
    }

    /** 请求创建角色回调 */
    respCreateRole(data) {
        cc.log('请求创建角色回调', data)
    }
}

/**
 * 新角色
 */
class NewRole {
    /** 角色id */
    private _id: number = null
    public get id() { return this._id }
    public set id(v: number) { this._id = v }

    /** 属性列表 */
    private _attrList: number[] = []
    public get attrList() { return this._attrList }
    public set attrList(v: number[]) { this._attrList = v }

    /** 名字 */
    private _name: string = null
    public get name() { return this._name }
    public set name(v: string) { this._name = v }

    addAttr(attrIndex: number) {
        this.attrList.push(attrIndex)
    }

    delAttr() {
        this.attrList.pop()
    }

    clearAttr() {
        this.attrList = []
    }
}
